package zj.com.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

import zj.com.model.DjcModel;
import zj.com.model.Gjgx;
import zj.com.util.DateUtil;
import zj.com.zj.R;

/**
 * Created by xi on 16/6/3.
 */
public class GjgxAdapter extends BaseAdapter{

    public List<Gjgx> list;
    public Context context;
    public LayoutInflater inflater;
    public boolean isEdit = false;

    public GjgxAdapter(List<Gjgx> list, Context context){

        this.list = list;
        this.context = context;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = new ViewHolder();
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.adapter_dqr_sggx_item, null);
           // viewHolder.type_iv = (ImageView) convertView.findViewById(R.id.type_iv);
            viewHolder.cb = (CheckBox) convertView.findViewById(R.id.cb);
            viewHolder.name_tv = (TextView) convertView.findViewById(R.id.name_tv);
            viewHolder.date_tv = (TextView) convertView.findViewById(R.id.date_tv);
            viewHolder.des_tv = (TextView) convertView.findViewById(R.id.des_tv);
            viewHolder.status_tv = (TextView) convertView.findViewById(R.id.status_tv);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }


        if(isEdit){
            viewHolder.cb.setVisibility(View.VISIBLE);
        }else{
            viewHolder.cb.setVisibility(View.GONE);

        }
        Gjgx gjgx =  list.get(position);
        viewHolder.name_tv.setText(gjgx.getName());

        String time = gjgx.getFinishedDate().replace("T"," ");
        if(time.equals("null")){
            viewHolder.date_tv.setText("");

        }else{
            viewHolder.date_tv.setText(DateUtil.formatStrimgDate2(time));

        }
        viewHolder.des_tv.setText(gjgx.getUnitProject()+">"+gjgx.getPartProject()+">"+gjgx.getSpecialProject());

        if(gjgx.getManagerCheckStatus() == 0){
            viewHolder.status_tv.setText("未阅");
        }else{
            viewHolder.status_tv.setText("已阅");

        }
        return convertView;
    }
    private static class ViewHolder {
        ImageView type_iv;
        TextView itemTitle;
        CheckBox cb;
        TextView name_tv;
        TextView date_tv;
        TextView des_tv;
        TextView status_tv;

    }

    public void setIsEdit(boolean isEdit){

        this.isEdit = isEdit;
        notifyDataSetChanged();
    }

    public void setDataChange(List<Gjgx> list){

        this.list = list;
        notifyDataSetChanged();
    }
}
